package com.app.TCES.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.app.TCES.domain.Course;
import com.app.TCES.domain.Department;
import com.app.TCES.service.AdministratorService;

@Controller
public class AdministratorController {
    @Autowired
	AdministratorService administratorService;
    
    
	@RequestMapping("/DepartmentSet")
	public String DepartmentSet(Model model) {
		model.addAttribute("Depart", administratorService.getDeparyment());
		return "/DepartmentSet";
	}
	

	@ResponseBody
	@RequestMapping("/teacherSet") //管理员教师管理
	public Map<String, Object> TeacherSet(@RequestParam("page")Integer page,@RequestParam("limit")Integer limit) {
		
		int tmp = (page-1)*limit;
		int tol = administratorService.gettol();
		

		List<com.app.TCES.domain.TeacherSet> teacher = administratorService.getTeacherSet(tmp,limit);

		 Map<String, Object> map = new HashMap<String, Object>();
		   map.put("tol",tol);
		   map.put("status",200);
		   map.put("message","成功");
		   map.put("teacher",teacher);
		   
		return map;
	}



	@RequestMapping("/teacher_dept")   //院系信息
	@ResponseBody
	public List<Department> teacher_dept(Model model) {

		return administratorService.getDeptName();
	}
	
	@RequestMapping("/Course")   //课程信息
	@ResponseBody
	public List<Course> SelectCourse(Model model) {

		return administratorService.getCourse();
	}
	
	@RequestMapping("/dept_teacher")   //院系信息
	@ResponseBody
	public Map<String, Object> dept_teacher(String deptName,@RequestParam("page")Integer page,@RequestParam("limit")Integer limit) {
		  System.out.println("1");
		  List<com.app.TCES.domain.TeacherSet> teacher;
		  int tmp = (page-1)*limit;
		  int tol;
		  if(deptName.equals("全部院系")==true) {
			  tol = administratorService.gettol();
			   teacher = administratorService.getTeacherSet(tmp,limit); 
		  }else {
			   tol = administratorService.gettol1(deptName);
			    teacher = administratorService.getTeacherSet1(tmp,limit,deptName); 
		  }


		 Map<String, Object> map = new HashMap<String, Object>();
		   map.put("tol",tol);
		   map.put("status",200);
		   map.put("massage","成功");
		   map.put("teacher",teacher);
		   
		return map;
	
	}
}
